package leaf.cloud.system.conntroller;

import leaf.cloud.common.core.Result;
import leaf.cloud.common.core.utils.StrUtils;
import leaf.cloud.common.core.web.controller.BaseController;
import leaf.cloud.common.system.domain.SysUser;
import leaf.cloud.common.system.model.LoginUser;
import leaf.cloud.system.service.SysUserService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Set;

/**
 * @ClassName SystemUserController
 * @Description
 * @Author YeZiHao
 * @Date 2023/2/26 16:55
 **/
@RestController
@RequestMapping("user")
public class SysUserController extends BaseController {

    @Resource
    private SysUserService userService;


    @GetMapping("info/{userName}")
    public Result<LoginUser> userInfo(@PathVariable String userName) {
        SysUser sysUser = userService.selectUserByUserName(userName);
        if (StrUtils.isNull(sysUser)) {
            return Result.fail("用户名或密码错误");
        }
        // 角色集合
        Set<String> roles =null;// permissionService.getRolePermission(sysUser);
        // 权限集合
        Set<String> permissions =null;// permissionService.getMenuPermission(sysUser);
        LoginUser sysUserVo = new LoginUser();
        sysUserVo.setSysUser(sysUser);
        sysUserVo.setRoles(roles);
        sysUserVo.setPermissions(permissions);
        return Result.success(sysUserVo);
    }
}
